package com.zxjia.ssmp.service.impl;

import com.zxjia.ssmp.dto.MemberAddressRequest;
import com.zxjia.ssmp.dto.MemberRequest;
import com.zxjia.ssmp.exception.BusinessException;
import com.zxjia.ssmp.feign.UserApiService;
import com.zxjia.ssmp.service.UserService;
import com.zxjia.ssmp.vo.MemberAddressVo;
import com.zxjia.ssmp.vo.MemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    UserApiService userApiService;

    @Override
    public List<MemberAddressVo> getMemberAddress(MemberAddressRequest request) {
        return userApiService.getMemberAddress(request);
    }

    @Override
    public MemberVo getMemberByMobile(MemberRequest memberRequest) {
        return userApiService.getMemberByMobile(memberRequest);
    }

    @Override
    public MemberVo login(MemberRequest memberRequest) {
        MemberVo memberVo = userApiService.getMemberByMobile(memberRequest);
        if(memberVo == null) {
            throw new BusinessException("用户不存在");
        }
        return memberVo;
    }

    @Override
    public MemberVo register(MemberRequest memberRequest) {
        MemberVo memberVo = userApiService.getMemberByMobile(memberRequest);
        if(memberVo != null) {
            throw new BusinessException("该账户已经存在了");
        }
        return userApiService.addMember(memberRequest);
    }

}
